﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using System.Windows.Forms;
using ANOWORD = Microsoft.Office.Interop.Word;

namespace HJ_SQL_ToTable
{
    public partial class ExportSQLToTableRibbon
    {
        private void ExportSQLToTableRibbon_Load(object sender, RibbonUIEventArgs e)
        {
            
        }

        private void btnExecute_Click(object sender, RibbonControlEventArgs e)
        {
            string sqlFile = string.Empty;
            string msg = string.Empty;

            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Title = "请选择SQL文件";
            ofd.Filter = "SQL文件(*.sql)|*.sql";

            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                sqlFile = ofd.FileName;
                if (SQLExportor.Export(sqlFile, ref msg))
                {
                    MessageBox.Show("导出成功！", "提示");
                    return;
                }

                if ( string.IsNullOrEmpty(msg))
                    MessageBox.Show("导出失败！", "提示");
                else
                    MessageBox.Show(msg, "提示"); 
            }
        }

        private void btnCopyTableInfo_Click(object sender, RibbonControlEventArgs e)
        {
            //if ( )
            ANOWORD.Document docu = Globals.ThisAddIn.Application.ActiveDocument;
            if (docu.Tables.Count < 2)
            {
                return;
            }

            MSWordTableCopyer copyer = new MSWordTableCopyer
            {
                 FromTableColumnIndex = 3,
                 FromTableIndex = 1,
                 FromTableRowIndex = 2,
                 ToTableColumnIndex = 2,
                 ToTableCount = 100,
                 ToTableRowIndex = 2,
                 ToTableStartIndex = 2
            };

            if (copyer.Copy(docu))
            {
                MessageBox.Show("拷贝成功", "提示");
            }
            else
            {
                MessageBox.Show("拷贝失败", "提示");
            }
        }
    }
}
